package com.youku.plugins.shareV4.view.components
{
   import flash.display.Sprite;
   import flash.utils.Dictionary;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.utils.AssetUtil;
   import flash.display.MovieClip;
   import flash.events.MouseEvent;
   import com.youku.utils.ReportUtil;
   import com.youku.events.PluginEvent;
   import com.youku.utils.OpenWindow;
   import flash.net.URLRequest;
   import flash.utils.ByteArray;
   import com.youku.utils.DrawUtil;
   
   public class IconList extends Sprite
   {
      
      public function IconList() {
         super();
         this._iconArr = [];
         this._dict = new Dictionary();
         this._nameDict = new Dictionary();
      }
      
      private var _iconArr:Array;
      
      private var _dict:Dictionary;
      
      private var _nameDict:Dictionary;
      
      private var _playerProxy:IPlayerProxy;
      
      public function init(param1:IPlayerProxy) : void {
         this._playerProxy = param1;
      }
      
      public function updateData(param1:String, param2:Number) : void {
         this._iconArr = [];
         var _loc3_:* = "http://hz.youku.com/red/click.php?tp=1&cp=4001984&cpp=1000208&url=";
         var _loc4_:* = "http://v.youku.com/v_show/id_" + this._playerProxy.playerData.videoIdEncode + ".html";
         if(param1 == "preview")
         {
            _loc4_ = _loc4_ + ("?firsttime=" + param2);
         }
         var _loc5_:String = this._playerProxy.playerData.videoTitle.length <= 32?this._playerProxy.playerData.videoTitle:this._playerProxy.playerData.videoTitle.substr(0,32);
         var _loc6_:String = this._playerProxy.playerData.videoLogoURL;
         var _loc7_:* = "http://player.youku.com/player.php/sid/" + this._playerProxy.playerData.videoIdEncode + "/v.swf";
         this._iconArr.push(
            {
               "name":"qzone",
               "icon":AssetUtil.getAsset("sharePanel_icon_Qzone"),
               "url":_loc3_ + encodeURIComponent("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + _loc4_)
            });
         this._iconArr.push(
            {
               "name":"qq",
               "icon":AssetUtil.getAsset("sharePanel_icon_qq"),
               "url":_loc3_ + encodeURIComponent("http://connect.qq.com/widget/shareqq/index.html?title=" + encodeURIComponent(_loc5_) + "&desc=" + encodeURIComponent("在优酷上看见这条视频还不错哦：" + _loc5_) + "&site=" + encodeURIComponent("优酷网") + "&url=" + _loc4_ + "&tpa=dW5pb25faWQ9MTAzMjUyXzEwMDAwMV8wMV8wMQ")
            });
         this._iconArr.push(
            {
               "name":"weibo",
               "icon":AssetUtil.getAsset("sharePanel_icon_weibo"),
               "url":_loc3_ + encodeURIComponent("http://v.t.sina.com.cn/share/share.php?appkey=2684493555&url=" + _loc4_ + "&ralateUid=1642904381&title=" + encodeURIComponent("【视频：" + _loc5_ + "】"))
            });
         this.createItems();
      }
      
      private function createItems() : void {
         var _loc2_:MovieClip = null;
         while(this.numChildren > 0)
         {
            this.removeChildAt(0);
         }
         this._dict = new Dictionary();
         this._nameDict = new Dictionary();
         var _loc1_:* = 0;
         while(_loc1_ < this._iconArr.length)
         {
            _loc2_ = this._iconArr[_loc1_].icon as MovieClip;
            _loc2_.x = _loc1_ * 30;
            _loc2_.y = 0;
            _loc2_.buttonMode = true;
            _loc2_.useHandCursor = true;
            this._dict[_loc2_] = this._iconArr[_loc1_].url;
            this._nameDict[_loc2_] = this._iconArr[_loc1_].name;
            this.addChild(_loc2_);
            _loc2_.addEventListener(MouseEvent.CLICK,this.onIconClick);
            _loc1_++;
         }
      }
      
      private function onIconClick(param1:MouseEvent) : void {
         var _loc2_:String = this._nameDict[param1.currentTarget];
         switch(_loc2_)
         {
            case "qq":
               ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_SHARE_TO_QQ);
               break;
            case "renren":
               ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_SHARE_TO_RENREN);
               break;
            case "weibo":
               ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_SHARE_TO_SINA);
               break;
            case "kaixin":
               ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_SHARE_TO_KAIXIN001);
               break;
            case "tianya":
               ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_SHARE_TO_TIANYA);
               break;
            case "qzone":
               ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_SHARE_TO_QZONE);
               break;
            case "tengxunweibo":
               ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_SHARE_TO_TENGXUNWEIBO);
               break;
            case "weixin":
               ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_SHARE_TO_WEIXIN);
               this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.ALERT_BOX_SHOW,
                  {
                     "type":"QRCode",
                     "from":"share"
                  }));
               return;
         }
         OpenWindow.open(new URLRequest(this._dict[param1.currentTarget]),"_blank");
      }
      
      private function gbkEncode(param1:String) : String {
         var _loc4_:* = 0;
         if(param1 == null || param1 == "")
         {
            return "";
         }
         var _loc2_:* = "";
         var _loc3_:ByteArray = new ByteArray();
         _loc3_.writeMultiByte(param1,"gbk");
         while(_loc4_ < _loc3_.length)
         {
            _loc2_ = _loc2_ + escape(String.fromCharCode(_loc3_[_loc4_]));
            _loc4_++;
         }
         return _loc2_;
      }
      
      private function getBackGround(param1:Number, param2:Number) : Sprite {
         var _loc3_:Sprite = new Sprite();
         var param1:Number = Math.round(param1);
         var param2:Number = Math.round(param2);
         _loc3_.addChild(DrawUtil.Line(0,0,param1,0,8421504,0.8,1));
         _loc3_.addChild(DrawUtil.Line(param1,0,param1,param2,8421504,0.8,1));
         _loc3_.addChild(DrawUtil.Line(param1,param2,0,param2,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Line(0,0,0,param2,8421504,0.8,1));
         _loc3_.addChild(DrawUtil.Rectangle(1,1,param1 - 2,param2 - 2,0,1,null,0));
         return _loc3_;
      }
   }
}
